package com.csxy.m2020_note;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.csxy.m2020_note.sql.NoteDbHelper;

public class NewActivity extends AppCompatActivity {
    private EditText titleEdit;
    private EditText bodyEdit;
    private Button confirmBtn;
    NoteDbHelper notedb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new);
        titleEdit = (EditText) findViewById(R.id.title);
        bodyEdit = (EditText) findViewById(R.id.body);
        confirmBtn = (Button) findViewById(R.id.confirm);
        //初始化数据库
        notedb=new NoteDbHelper(NewActivity.this);
        notedb.open();

        confirmBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String title=  titleEdit.getText().toString();
                String body=bodyEdit.getText().toString();

                int id=notedb.createNote(title,body);
            //关闭数据库
                notedb.close();
                Log.e("NewActivity",title+" "+body+" id="+id);
                finish();
            }
        });
    }
}
